/*
 * This file is part of aKoustiK.

 * aKoustiK is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * aKoustiK is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with aKoustiK.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef XSPFSTORAGE_H
#define XSPFSTORAGE_H

#include <QtCore/QList>
#include <QtCore/QString>
#include <QtCore/QXmlStreamReader>
#include <QtCore/QXmlStreamWriter>

#include <item.h>

/**
  Class responsible for handling of XSPF playlist format.
  It has 2 properties: name of playlist and list of items.
  load() method reads from specified file and overrides those
  properties from playlist it read.
  store() method writes playlistName and playlistItems to
  specified file.
  */
class XspfStorage {

public:
    XspfStorage(const QString& targetFile);
    ~XspfStorage();

    /** Method to load playlist from specified file.
      It will override both playlistName and playlistItems. */
    void load();
    /** Method to write playlist to specified file.
      It will write both playlistName and playlistItems.
      */
    void store();

    const QString& name() const;
    void setName(const QString& value);
    const QList<Item*> items() const;
    void setItems(const QList<Item*>& value);

private:
    QString filePath;
    QString playlistName;
    QList<Item*> playlistItems;

    void writeItem(Item* item, QXmlStreamWriter& writer);
    Item* readItem(QXmlStreamReader& reader);
};

#endif
